package  
{
	import net.flashpunk.tweens.misc.VarTween;
	import net.flashpunk.World;
	import net.flashpunk.World;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.Sfx;
	import net.flashpunk.Tween;
	
	
	/**
	 * ...
	 * @author Donatello
	 */
	public class FinalScene extends World
	{
		[Embed(source = "img/final.png")]private const IMG_BACK:Class;
		private var imgBack:Image;
		
		[Embed(source = "sfx/explosion.mp3")] private static const SFX:Class;
		private var sfx:Sfx= new Sfx(SFX);
	
		private var time:Number = 0.0;
		private var agregada:Boolean = false;
		
		private var music:Music2 = new Music2;
		
		private var tween1:VarTween;
	
		
		public function FinalScene() 
		{			
			imgBack = new Image(IMG_BACK);
			imgBack.x = 0;
			imgBack.y = 0;
			
			add(new Dialog("Grave error", 350, 300, 1, 300));
		
			tween1 = new VarTween();
			addTween(tween1);
			
		}
		
		
		override public function update():void
		{
			time += FP.elapsed;
			
			if (time > 1 && !agregada)
			{
				addGraphic(imgBack);
				
				add(new Explosion( -700, -500));
				sfx.play();
				music.changeVolume(2);
				time = 0.0;
				agregada = true;
				
				tween1.tween(imgBack, "alpha", 0, 5);
				
				
			}
			
			if (time >= 5 && agregada)
			{
				
				
				FP.world = new EndScene();
				removeAll();
			}
		
			
			
			
			super.update();
		}
	}

}